<template>
  <div class="article-item" @click="readViewClick(article)">
    <div class="cover">
      <img v-lazy="article.cover" alt="" />
      <p>{{ article.title }}</p>
    </div>
    <div class="content">
      <div class="desc">{{ article.desc }}</div>
      <div class="info">
        <div
          class="username"
          @click.stop.self="router.push('/info/' + article.uid)"
        >
          <img class="read" v-lazy="usersvg" alt="" />
          {{ article.username }}
        </div>
        <div>
          <img class="read" :src="clocksvg" alt="" />
          {{ formatDateYMD(article.createTime) }}
        </div>
        <div>
          <img class="read" :src="tagsvg" alt="" />
          <template v-for="tag in article.tags">
            <span @click.stop.self="tagClick(tag)" class="item-tag">{{
              tag
            }}</span>
          </template>
        </div>
        <div>
          <img class="read" :src="readsvg" alt="" />
          {{ article.read }}
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { formatDateYMD } from "@/utils/format";
import router from "@/router";
import { IArticle } from "@/store";
import readsvg from "@/assets/img/read.svg";
import tagsvg from "@/assets/img/tag.svg";
import usersvg from "@/assets/img/user.svg";
import clocksvg from "@/assets/img/clock.svg";
import { addReadingService } from "@/service/article";
const { article } = defineProps<{
  article: any;
}>();
const tagClick = async (tag: string) => {
  router.push({
    path: "/tag",
    query: {
      tag
    }
  });
};
const readViewClick = (article: IArticle) => {
  addReadingService(article.id);
  router.push(`/readview?id=${article.id}&uid=${article.uid}`);
};
</script>

<style scoped lang="less">
.article-item {
  position: relative;
  width: 100%;
  height: 320px;
  border-radius: 10px;
  background-color: gray;
  background-size: cover;
  margin-top: 20px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  transition: all 0.3s linear;
  overflow: hidden;
  z-index: 1;
  border: 2px solid transparent;

  &:hover {
    // transform: scale(1.05);
    // transform: perspective (500px) translateZ(100px);
    box-shadow: 0 0 10px 5px rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(25, 137, 250, 0.5);
  }
  .cover {
    display: flex;
    width: 100%;
    height: 100%;
    font-size: 20px;
    text-align: center;
    color: #fff;
    background-color: rgba(0, 0, 0, 0.4);
    transition: all 0.2s ease-out;
    cursor: pointer;
    img {
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      z-index: -1;
    }

    p {
      margin: auto 30px;
      width: 100%;
      transition: all 0.3s linear;
    }
  }
  .content {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 10px;
    padding: 0 20px;
    font-size: 16px;
    color: #fff;
    .desc {
      padding: 10px 0;
      border-bottom: 1px solid #fff;
    }
    .info {
      position: relative;
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      z-index: 98;
      padding: 10px 0 0;
      font-size: 14px;
      > div {
        margin-right: 2px;
      }
      .username {
        cursor: pointer;
      }
      .item-tag {
        margin: 0 5px;
        cursor: pointer;
        transform: scale(1);
        &:hover {
          color: #1989fa;
        }
      }
      .read {
        width: 20px;
        vertical-align: middle;
        margin-right: 5px;
      }
    }
  }
}
</style>
